package net.superdvach.content;

import java.io.*;

public class ItemFactory {
	
	public static ItemPost makePost(byte[] bytes) throws IOException {
		Item item = makeItem(bytes);
		if((item != null) && (item instanceof ItemPost))
			return (ItemPost)item;
		return null;
	}
	
	public static ItemThread makeThread(byte[] bytes) throws IOException {
		Item item = makeItem(bytes);
		if((item != null) && (item instanceof ItemThread))
			return (ItemThread)item;
		return null;
	}
	
	public static Item makeItem(byte[] data) throws IOException {
		ByteArrayInputStream instream = new ByteArrayInputStream(data);
		ObjectInputStream in = new ObjectInputStream(instream);
		Item item = null;
		try {
			item = (Item)in.readObject();
		}
		catch(ClassNotFoundException e)	{
			e.printStackTrace();
		}
		return item;
	}
	
}
